package org.wltea.expression.function;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.Date;

/**
 * <P>描述</P>
 * User: tianhuaxing
 * Date: 2018/1/9
 * Time: 16:44
 */
public class ComparatorDate implements Comparator {
    public int compare(Object obj1, Object obj2) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date begin = format.parse(obj1 + "");
            Date end = format.parse(obj2 + "");
            if (begin.after(end)) {
                return -1;
            } else {
                return 1;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return -1;
    }
}

